﻿using System;
using System.IO;
using log4net;
using log4net.Config;

namespace SDL
{
    public static class Log
    {
        private const string _Lock = "блокировка:)";
        private static bool _Init;

        public static ILog GetLogger(Type type)
        {
            if (!_Init)
            {
                lock (_Lock)
                {
                    if (!_Init)
                    {
                        var filename = "";
                        var file = new FileInfo(SDLSettings.WorkingDirectory + @"bin\log4net.xml");
                        if (file.Exists) filename = file.FullName;

                        if (!string.IsNullOrEmpty(SDLSettings.LogSettingsFile))
                        {
                            file = new FileInfo(SDLSettings.LogSettingsFile);
                            if (file.Exists) filename = file.FullName;
                        }
                        if (!string.IsNullOrEmpty(filename))
                        {
                            XmlConfigurator.Configure(new FileInfo(filename));
                        }
                        _Init = true;
                    }
                }
            }
            return (LogManager.GetLogger(type));
        }
    }
}
